home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Presentations / Presentations ’96 / Sessions ’96 / MacOS 8 Sessions / MacOS 8 Extensions / Demo Patch Code / DemoPatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-16  |  2.4 KB  |  117 lines  |  [TEXT/MPCC]

  1. #define FOR_SYSTEM8_PREEMPTIVE    1
  2.  
  3. #include    <LowMem.h>
  4. #include    <Types.h>
  5. #include    <Patches.h>
  6. #include    <CodeFragments.h>
  7. #include    <Sound.h>
  8.  
  9. #include    "MMSharedData.h"
  10. #include     "DemoPatchL.h"
  11.  
  12. void LocalMoreMastersPatch(void);
  13. void DoSomePreprocessing(void);
  14. void DoSomePostprocessing(void);
  15.  
  16. unsigned long            gMyAppNumber;
  17.  
  18. enum {
  19.     kMyPatchCount    =    1        /* Number of patches in my list */
  20. };
  21.  
  22. /*
  23.  *    One patch description per patch
  24.  */
  25. PatchDescription    gMoreMastersPatchDescription = {
  26.                                 &MoreMasters,
  27.                                 &LocalMoreMastersPatch,
  28.                                 {
  29.                                     'wild',
  30.                                     'demo'
  31.                                 },
  32.                                 {
  33.                                     kNilOptions,
  34.                                     {
  35.                                         kDoNotMatchAnyOrderedItemService,
  36.                                         kDoNotMatchAnyOrderedItemSignature
  37.                                     },
  38.                                     {
  39.                                         kDoNotMatchAnyOrderedItemService,
  40.                                         kDoNotMatchAnyOrderedItemSignature
  41.                                     }
  42.                                 },
  43.                                 kPatchEnabledMask,
  44.                                 paramErr,
  45.                                 kInvalidID,
  46.                                 NULL,
  47.                                 kInvalidID
  48.                             };
  49.  
  50. /*
  51.  *    The table with the list of patch descriptions (degenerate here as there is only one patch)
  52.  */
  53. PatchDescription *    gPatchDescriptionList[kMyPatchCount] = {
  54.                                 &gMoreMastersPatchDescription
  55.                             };                            
  56.  
  57. /*
  58.  *    The Patch Data block. This is exported as the patch fragment's main entry point
  59.  */
  60. PatchHeader gPatchData =     {    
  61.                             kPatchHeaderTag,
  62.                             kPatchHeaderVersion,
  63.                             kNilOptions,
  64.                             kMyPatchCount,
  65.                             &gPatchDescriptionList[0]
  66.                             };
  67.  
  68.  
  69.  
  70. /*
  71.  *    The patch itself.
  72.  *    Does some preprocessing, calls through to the rest of the patch chain, and
  73.  *    then does some postprocessing.
  74.  */
  75.  
  76. void LocalMoreMastersPatch(void)
  77. {
  78. //    Debugger();
  79.  
  80.     if (gMMAppList[gMyAppNumber].appName[0] == 0)
  81.     {
  82.         BlockMoveData(LMGetCurApName(),&gMMAppList[gMyAppNumber].appName,
  83.                       sizeof(gMMAppList[gMyAppNumber].appName));
  84.     }
  85.  
  86.     gMMAppList[gMyAppNumber].appMMCount++;
  87.  
  88. // Call through
  89.     (*(MoreMastersPatchProcPtr) gMoreMastersPatchDescription.thisCallThroughProc)();
  90. }
  91.  
  92. /*
  93.  *    CFM init routine.
  94.  *
  95.  *    Do not proceed if the patch could not be installed.
  96.  */
  97.  
  98. OSErr InitMyPatch(const CFragOpaqueInitBlock *initBlock)
  99. {
  100. #pragma unused ( initBlock )
  101.  
  102.     Debugger();
  103.     if (gMoreMastersPatchDescription.installResult == noErr)
  104.     {
  105.         unsigned long            myAppNumber;
  106.  
  107.         myAppNumber = ++gMMNextAppNumber;
  108.         if (myAppNumber >= NUMAPPS)
  109.         {
  110.             gMMNextAppNumber = myAppNumber = 0;
  111.         }
  112.         gMyAppNumber = myAppNumber;
  113.     }
  114.  
  115.     return (gMoreMastersPatchDescription.installResult);
  116. }
  117.